package com.example.demo.config;

import com.example.demo.common.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

/**
 * 全局配置文件
 *
 * @author CY
 * @date 2023/03/14 21:06
 **/
@Configuration
public class AppConfig implements WebMvcConfigurer {
    @Autowired
    private LoginInterceptor loginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        final InterceptorRegistration interceptorRegistration = registry.addInterceptor(loginInterceptor);
        interceptorRegistration.addPathPatterns("/**");
        List<String> list = new ArrayList<String>() {
            {
                add("/user/login");
                add("/user/reg");
                add("/**/*.html");
                add("/css/**");
                add("/editor.md/**");
                add("/img/**");
                add("/mapper/**");
                add("/js/**");
                add("art/detailbyid");
                add("art/get-detail");
                add("art/list");
            }
        };
        interceptorRegistration.excludePathPatterns(list);
    }
}
